<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3_回调ref中回调执行次数的问题</title>
</head>
<body>
  <div id="test"></div>

  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <!-- Don't use this in production: -->
  <script src="../js/babel.min.js"></script>
  <!-- 引入prop-types.js  用于对组件标签属性进行限制 -->
  <script src="../js/prop-types.js"></script>

  <script type="text/babel">
    // 创建组件
    class Demo extends React.Component {
      state = {
        isHot: false
      }

      changeWeather = () => {
        const {isHot} = this.state
        this.setState({
          isHot: !isHot
        })
      }

      showInfo = () => {
        const {input} = this
        alert(input.value)
      }

      saveInput = (c) => {
        this.input = c
        console.log('@', c)
      }

      render() {
        const {isHot} = this.state
        return (
          <div>
            <h2 onClick={this.changeWeather}>今天天气很{isHot ? "炎热" : "凉爽"}</h2>
            {/*<input ref={ (currentNode) => {this.input = currentNode; console.log('@', currentNode)} } type="text" />*/}
            <input ref={this.saveInput} type="text" />
            <button type="button" onClick={this.showInfo}>点我显示数据</button>
          </div>
        )
      }
    }

    // 渲染组件到页面
    ReactDOM.render(<Demo/>, document.getElementById("test"))
  </script>
</body>
</html>